package br.com.emmis.tercons.controller;

import android.content.Context;
import android.media.MediaPlayer;

import br.com.emmis.tercons.model.interfaces.Pray;

/**
 * Created by vaner on 11/12/2014.
 */
public class TercoPlayer {

    private Context mContext;
    private MediaPlayer mMediaPlayer;

    public TercoPlayer(Context context) {
        mMediaPlayer = new MediaPlayer();
        mContext = context;
    }

    public void playPray(Pray pray){
        stopPray();
        int id = pray.soundId();
        if(id > 0) {
            mMediaPlayer = MediaPlayer.create(mContext, id);
            mMediaPlayer.start();
        }
    }

    public void stopPray(){
        if(mMediaPlayer != null && mMediaPlayer.isPlaying()) {
            mMediaPlayer.stop();
            releaseTercoPlayer();

        }
    }

    public void pausePray() {
        if(mMediaPlayer != null && mMediaPlayer.isPlaying()) {
            mMediaPlayer.pause();
        }
    }

    public void resumePray() {
        if (mMediaPlayer != null) {
            mMediaPlayer.start();
        }
    }

    public void releaseTercoPlayer() {
        if(mMediaPlayer != null) {
            mMediaPlayer.release();
            mMediaPlayer = null;
        }
    }
}
